package com.stanley.demo.app.model

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import javax.inject.Inject

class UserRepository @Inject constructor(
    private val webService:WebService
){

    fun getUser(userId:String):LiveData<User> {
        val data = MutableLiveData<User>()
        webService.getUser(userId).enqueue(object: Callback<User>{
            override fun onResponse(call: Call<User>, response: Response<User>) {
                data.value = response.body()
            }

            override fun onFailure(call: Call<User>, t: Throwable) {
                //TODO("Not yet implemented")
                Log.e("UserRepository", "err msg: " + t.message)
            }
        })
        return data
    }
}